// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   CommonDaoImplV2.java

package mycommon.model.orm.impl;

import java.util.Iterator;
import java.util.List;
import mycommon.factory.HibernateSessionFactory;
import mycommon.model.orm.CommonDaoV2;
import mycommon.util.CommonDaoUtil;
import org.hibernate.Query;
import org.hibernate.Session;

// Referenced classes of package mycommon.model.orm.impl:
//			CommonDaoImpl

public class CommonDaoImplV2 extends CommonDaoImpl
	implements CommonDaoV2
{

	public CommonDaoImplV2()
	{
	}

	public List loadByPage(Class cla, int startPage, int pageSize, String property)
	{
		List all;
		Session s;
		all = null;
		s = HibernateSessionFactory.getSession();
		try
		{
			Query q = s.createQuery((new StringBuilder("from ")).append(CommonDaoUtil.extractObject(cla)).append(" order by ").append(property).append(" desc").toString());
			q.setFirstResult(startPage - 1);
			q.setMaxResults(pageSize);
			all = q.list();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		
		HibernateSessionFactory.closeSession();
		return all;
	}

	public List loadByPage(Class cla, int startPage, int pageSize, String property, Class associate[])
		throws Exception
	{
		if (associate == null || associate.length == 0)
			return loadByPage(cla, startPage, pageSize, property);
		Session s = HibernateSessionFactory.getSession();
		Query q = s.createQuery((new StringBuilder("from ")).append(CommonDaoUtil.extractObject(cla)).append(" order by ").append(property).append(" desc").toString());
		q.setFirstResult(startPage - 1);
		q.setMaxResults(pageSize);
		List results = q.list();
		for (Iterator it = results.iterator(); it.hasNext(); initlize(it.next(), associate));
		HibernateSessionFactory.closeSession();
		return results;
	}
}
